package com.snailhd.cloud.id.configuration;

import com.snailhd.cloud.id.util.SnowflakeIdWorker;
import lombok.Getter;
import lombok.Setter;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Slf4j
@Setter
@Getter
@Configuration
@ConfigurationProperties(prefix = SnowflakeConfig.PREFIX)
public class SnowflakeConfig {

    public final static String PREFIX = "snailhd.cloud.id-service";

    private Long workerId;

    private Long datacenterId;

    @Bean
    public SnowflakeIdWorker init(){
        log.info("---------> SnowflakeIdWorker 注入成功：workerId={},datacenterId={}",workerId,datacenterId);
        return new SnowflakeIdWorker(workerId,datacenterId);
    }

}
